<%@ page pageEncoding="utf-8"%>
<%@ page import="java.net.InetSocketAddress"%>
<%@ page import="java.net.SocketAddress"%>
<%@ page import="java.net.URL"%>
<%@ page import="java.text.DecimalFormat"%>
<%@ page import="java.util.List"%>
<%@ page import="org.jawa.core.*"%>
<%@ page import="org.jawa.core.util.ClassUtils"%>
<%@ page import="java.lang.reflect.Method"%>

<%
	// 系统已安装
	if (!JawaServer.getInstance().isSetupMode()) {
        response.sendRedirect("setup-completed.jsp");
        return;
    }
%>

<!DOCTYPE html>
<html lang="en">
	<head>
		<title>检查安装环境</title>
		<meta name="currentStep" content="1" />
	</head>
	<body>
		<div class="row-fluid">
			<div class="page-header">
				<h3>
					检查安装环境
				</h3>
			</div>

				<table class="table  well">
					<tbody>
						<tr>
							<td>
								<span>操作系统</span>
							</td>
							<td><%=System.getProperty("os.name")%>
								/
								<%=System.getProperty("os.arch")%>
							</td>
						</tr>
						<tr>
							<td>
								<span>JAVA 虚拟机</span>
							</td>
							<td>
								<%
									String vmName = System.getProperty("java.vm.name");
									if (vmName == null) {
										vmName = "";
									} else {
										vmName = " -- " + vmName;
									}
								%>
								<%=System.getProperty("java.version")%>
								<%=System.getProperty("java.vendor")%><%=vmName%>
							</td>
						</tr>
						<tr>
							<td>
								<span> Servlet 容器</span>
							</td>
							<td><%=application.getServerInfo()%> (<%=application.getMajorVersion() %>.<%=application.getMinorVersion() %>)</td>
						</tr>
						<tr>
							<td>
								<span>虚拟机内存</span>
							</td>
							<td>
								<%
									Runtime runtime = Runtime.getRuntime();

									double freeMemory = (double) runtime.freeMemory() / (1024 * 1024);
									double maxMemory = (double) runtime.maxMemory() / (1024 * 1024);
									double totalMemory = (double) runtime.totalMemory() / (1024 * 1024);
									double usedMemory = totalMemory - freeMemory;
									double percentFree = ((maxMemory - usedMemory) / maxMemory) * 100.0;
									double percentUsed = 100 - percentFree;
									int percent = 100 - (int) Math.round(percentFree);

									DecimalFormat mbFormat = new DecimalFormat("#0.00");
									DecimalFormat percentFormat = new DecimalFormat("#0.0");

									String cssClass = "";
									if (percent >= 90) {
										cssClass = " progress-danger";
									} else {
										cssClass = " progress-info";
									}
								%>
								<div class=" progress <%=cssClass%>"
									style="border: 1px solid #DDDDDD; padding: 1px">
									<div class="bar"
										style="width: <%=percentFormat.format(percentUsed)%>%;"><%=percentFormat.format(percentUsed)%>%
									</div>
								</div>
								<div style="">
									使用
									<%=mbFormat.format(usedMemory)%>
									MB 共
									<%=mbFormat.format(maxMemory)%>
									MB (<%=percentFormat.format(percentUsed)%>%)
								</div>
							</td>
						</tr>
					</tbody>
				</table>

			<form action="setup-datasource-settings.jsp" method="post">
				<%
					String ver = System.getProperty("java.version");
					if (ver.compareTo("1.6") <= 0) {
				%>
				<div class="alert alert-error">
					<span class="badge badge-error">1</span>JDK 必须高于 1.6
				</div>
				<%
					} else if (application.getMajorVersion()<2 || ( application.getMajorVersion() == 2 && application.getMinorVersion()<5  ) ){
				%>
				<div class="alert alert-error">
					<span class="badge badge-error">1</span>Servlet 容器版本至少需要2.5
				</div>
				<%
					} else {
				%>
				<div class="form-actions">
					<input type="submit" name="save" value="下一步" id="jawa-setup-save" class="btn btn-primary " >
				</div>
				<%
					}
				%>
			</form>

		</div>

	</body>
</html>
